#include "processbar.h"
#include <string.h>
#include <unistd.h>

const char* p="|/-\\";

// version 1
void processbar()
{
    char buffer[N];
    memset(buffer,'\0',sizeof(buffer));
    int cnt=0;
    while (cnt<=100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,p[cnt%4]);
        fflush(stdout);
        usleep(50000);
        buffer[cnt++]=lable;
    }
    printf("\n");
}

int cnt=0;
// version 2
void processbar_flush(float bit)
{
    char buffer[N];
    int need=(int)(bit*100);
    memset(buffer,'\0',sizeof(buffer));
    memset(buffer,'#',(size_t)need);
    printf("[%-100s][%d%%][%c]\r",buffer,need,p[cnt%4]);
    fflush(stdout);
    usleep(100000);
    ++cnt;
    cnt%=4;
}
